package com.saodisheng.enums;

import java.util.Arrays;
import java.util.HashMap;

/**
 * description:
 * 年级枚举类
 *
 * @author 01420175_liuxingwu
 * @date 2022/2/8
 */
public enum GenderEnum {
    /** 男 **/
    M("Male", 1),
    /** 女 **/
    FM("Female", 0);

    private String name;
    private Integer value;

    GenderEnum(String name, Integer value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public static String getNameByValue(Integer value) {
        for (GenderEnum type : GenderEnum.values()) {
            if (type.getValue().equals(value)) {
                return type.getName();
            }
        }
        return null;
    }

    public static Integer getValueByName(String name) {
        GenderEnum[] gradeEnumArr = GenderEnum.values();
        HashMap<String, Integer> enumMap = new HashMap<>();
        Arrays.stream(gradeEnumArr).forEach(e -> {
            String nameStr = getNameByValue(e.value);
            enumMap.put(nameStr, e.value);
        });
        return enumMap.get(name);
//        return GradeEnum.valueOf(name).value;
    }
}
